package com.tianlan.blog.dao;

import java.util.List;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.tianlan.blog.entity.SysOrganization;

public interface SysOrganizationDao extends JpaRepository<SysOrganization, Long>{
		
	@Query(value = "CALL queryOrganizationList(:parentId)", nativeQuery = true)
	List<SysOrganization> queryOrganizationTreeProc(@Param("parentId") Integer parentId);
	
	long countByIdAndDelFlag(Integer id,String delFlag);
	
	long countByOrganizationNameAndOrganizationKeyAndDelFlag(String organizationName,String organizationKey,String delFlag);

	@Transactional
	@Modifying
	@Query(value = "UPDATE sys_organization SET del_flag = 1 WHERE  id in (?1)"
	,nativeQuery = true)
	int removeByIds(List<Integer> orgIds);
	
	long count(Specification<SysOrganization> specification);

}
